package com.fram.controller.admin.botany;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.admin.botany.request.BotanyCategorySearchRequest;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProAffairException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.BotanyCategory;
import com.fram.service.admin.botany.BotanyCategoryService;

/**
 * @作者： 陳曉鬆 @时间： 2020年7月2日 - 下午3:16:47 @description：-> 植物类型
 */
@RestController
@RequestMapping("/admin/botany/{version}/category")
public class BotanyCategoryController {

	private static Logger LOG = LoggerFactory.getLogger(BotanyCategoryController.class);

	@Resource
	private BotanyCategoryService botanyCategoryService;

	@ApiVersion(1.0)
	@RequestMapping(value = "/add")
	private ResponseMsg add(@RequestBody BotanyCategory request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			botanyCategoryService.insertCategory(request);
		} catch (ProAffairException e) {
			LOG.error("-植物类型-add出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-植物类型-add异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping(value = "/list")
	private ResponseMsg list(@RequestBody BotanyCategorySearchRequest request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(botanyCategoryService.list(request));
		} catch (ProAffairException e) {
			LOG.error("-植物类型-list出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-植物类型-list异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

}
